package com.sigmazero13.bgjeeves;

import java.util.List;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;

import com.sigmazero13.bgjeeves.RenameAddDialog.OnRenameAddListener;

public class PlayerList extends RenamableInfoList {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
			@Override
			public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
				String thisItem = (String)parent.getItemAtPosition(position);
				openRenameDialog(thisItem);
				return true;
			}
		});
	}

	@Override
	protected String getRenameDialogTitle() {
		return getString(R.string.rename_dialog_title_player);
	}

	@Override
	protected OnRenameAddListener getDialogRenameAddListener() {
		return new OnRenameAddListener() {
			@Override
			public void onRename(String origName, String newName) {
				((BoardGameUtilsApp)PlayerList.this.getApplication()).getDbHelper().renamePlayer(origName, newName);
				updateList();
			}
			
			@Override
			public void onAdd(String newName) {
				throw new UnsupportedOperationException("Cannot add new players");
			}
		};
	}

	@Override
	protected List<String> getList() {
		return ((BoardGameUtilsApp)PlayerList.this.getApplication()).getDbHelper().getPlayerNames();
	}
}
